home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8434 / 8434.xpi / chrome / content / repair.js < prev    next >
Text File  |  2008-11-16  |  3KB  |  72 lines

  1. var ds, container, styleCount, enumerator, progress, numberDone, style;
  2. function init() {
  3.     ds = GoogleRedesignedStyle.prototype.ds;
  4.     container = ds.getNode(GoogleRedesignedStyle.prototype.containerURI);
  5.     styleCount = container.getChildCount();
  6.     enumerator = ds.getAllResources();
  7.     progress = document.getElementById("progress");
  8.     numberDone = 0;
  9.     repairNext();
  10. }
  11. function repairNext() {
  12.     if (!enumerator.hasMoreElements()) {
  13.         ds.save();
  14.         close();
  15.         return;
  16.     }
  17.     var node = enumerator.getNext();
  18.     if (node.source.Value == container.source.Value) {
  19.         repairNext();
  20.         return;
  21.     }
  22.     if (container.getChildIndex(node) == -1) {
  23.         ds.deleteRecursive(node);
  24.         repairNext();
  25.         return;
  26.     }
  27.     style = new GoogleRedesignedStyle(node);
  28.     if (!style.code) {
  29.         ds.deleteRecursive(style.node);
  30.         numberDone++;
  31.         progress.setAttribute("value", (0 + numberDone) / styleCount * 100 + "%");
  32.         repairNext();
  33.         return;
  34.     }
  35.     if (style.updateURL) {
  36.         if (/http:\/\/userstyles.org\/style\/show\/[0-9]+\?raw/.test(style.updateURL)) {
  37.             style.updateURL = style.updateURL.replace("/style/", "/styles/").replace("/show/", "/").replace("?raw", ".css");
  38.             style.save();
  39.         } else if (/http:\/\/userstyles.org\/style\/raw\/[0-9]+/.test(style.updateURL)) {
  40.             style.updateURL = style.updateURL.replace("/style/", "/styles/").replace("/raw/", "/") + ".css";
  41.             style.save();
  42.         } else if (/http:\/\/userstyles.org\/styles\/raw\/[0-9]+/.test(style.updateURL)) {
  43.             style.updateURL = style.updateURL.replace("/raw/", "/") + ".css";
  44.             style.save();
  45.         }
  46.     }
  47.     if (/http:\/\/userstyles.org\/style\/show\/[0-9]+/.test(style.uri)) {
  48.         var newStyle = new GoogleRedesignedStyle(style.uri.replace("/style/", "/styles/").replace("/show/", "/"));
  49.         style.copy(newStyle);
  50.         GoogleRedesignedStyle.prototype.ds.deleteRecursive(style.node);
  51.         newStyle.save();
  52.         repairNext();
  53.         return;
  54.     }
  55.     check();
  56. }
  57. function check() {
  58.     var doc = document.implementation.createDocument(googleredesignedCommon.XULNS, "googleredesigned-parse", null);
  59.     var link = doc.createElementNS(googleredesignedCommon.HTMLNS, "link");
  60.     link.rel = "stylesheet";
  61.     link.type = "text/css";
  62.     link.href = googleredesignedCommon.codePrefix + style.code;
  63.     var loadedListener = new GoogleRedesignedStylesheetLoadedListener(doc, null, loaded);
  64.     doc.documentElement.appendChild(link);
  65.     loadedListener.checkStyleLoaded();
  66. }
  67. function loaded(success, data) {
  68.     style.calculateMetadata(data.stylesheet);
  69.     numberDone++;
  70.     progress.setAttribute("value", (0 + numberDone) / styleCount * 100 + "%");
  71.     repairNext();
  72. }